//
//  JWRateStarAlertView.m
//  DxyClient
//
//  Created by Xu Jiwei on 11-6-27.
//  Copyright 2011 Xujiwei.com. All rights reserved.
//

#import "JWRateStarAlertView.h"

#import "JWRateStarView.h"


@implementation JWRateStarAlertView

@synthesize rateAlertDelegate;

- (id)initWithTitle:(NSString *)title starCount:(NSUInteger)starCount delegate:(id<JWRateStarAlertViewDelegate>)delegate {
    if (self = [super initWithTitle:@"请选择评分"
                            message:@"\n\n"
                           delegate:self
                  cancelButtonTitle:@"取消"
                  otherButtonTitles:@"确定", nil]) {
        
        rateStarView = [[JWRateStarView alloc] initWithFrame:CGRectMake(0, 54, self.bounds.size.width, 24)];
        rateStarView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
        rateStarView.starGap = 8.0;
        rateStarView.enableRate = YES;
        rateStarView.totalStarCount = starCount;
        [self addSubview:rateStarView];
        [rateStarView release];
        
        self.rateAlertDelegate = delegate;
    }
    
    return self;
}


- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {
    if (buttonIndex == alertView.cancelButtonIndex) {
        if ([self.rateAlertDelegate respondsToSelector:@selector(rateStarAlertViewDidCancel:)]) {
            [self.rateAlertDelegate rateStarAlertViewDidCancel:self];
        }
        
    } else {
        if ([self.rateAlertDelegate respondsToSelector:@selector(rateStarAlertView:didDismissWithRate:)]) {
            [self.rateAlertDelegate rateStarAlertView:self didDismissWithRate:rateStarView.rate];
        }
    }
}


@end
